package cn.lianxi.mrv2._04_;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class IntSumReducer extends Reducer<MyWritable, IntWritable, Text, Text> {

	Text v = new Text();

	@Override
	protected void reduce(MyWritable key, Iterable<IntWritable> values,
			Context context) throws IOException, InterruptedException {

		Iterator<IntWritable> it = values.iterator();
		List<String> lists = new ArrayList<String>();

		while (it.hasNext()) {
			// lists.add(it.next().getNumber() + "");
		}

		String result = "{ " + lists.get(0);
		for (int i = 1; i < lists.size(); i++) {
			result += ("," + lists.get(i));
		}
		result += " }";
		v.set(result);
		// context.write(key, v);
	}
}
